{include file="./headStart.tpl"}
<script type="text/javascript">
   $(document).ready(function(){
    // To change subcategory : Starts
    
      $(".classSubcategory").change(function(){
        subCategoryCombo($(this));
      });
      {if $newInstallInComplete == 1}
        $(".classItem").change(function(){
          itemCombo($(this));
        });
      {/if}
    // To change subcategory : End  
    $(".add").click(function(){ 
      $("#one").clone(true).appendTo("#mainDiv").find('input[type="text"]').val('');    
      addRow();
    });
   });
function deleteRow() 
{
  $('.delete').click(function()
  {
    var countSr = 1;
    $(this).parent().parent().remove();
    $('.srNoClass').each(function(){
          this.value = countSr++;
        });
    return false;
  });
}
function addRow() 
{
  var countSr = 1;
    $('.srNoClass').each(function()
    {
      this.value = countSr++;
    });
    return false;
}  
// To change item : Starts
function subCategoryCombo(theObj) 
{
  var dataString = "categoryId=" + $(theObj).val();
  $.ajax({
    url: "./subCategoryAjDelivery.php",
    cache: false,
    data: dataString,
    success:function(data){
    	$(theObj).next("span").html(data);
    	$(theObj).next("span").focus();
      $(".classItem").change(function(){
        itemCombo($(this));
      });
    }
  });
}
// To change item : Ends
function itemCombo(itemObj) 
{
  var dataString1 = "subCategoryId=" + $(itemObj).val();
  $.ajax({
    url: "./itemAj.php",
    cache: false,
    data: dataString1,
    success:function(data){
    	$(itemObj).parent().next("span").html(data);
    	$(itemObj).parent().next("span").focus();
    }
  });
}
</script>
{include file="./headEnd.tpl"}
<form name="form" action="{$smarty.server.PHP_SELF}" id="form" method="post">
<input type="hidden" name="newinstallationMasterId" value="{$newinstallationMasterId}" />
<input type="hidden" name="newInstallComplete" value="{$newInstallComplete}" /> 
<input type="hidden" name="newInstallInComplete" id="newInstallInComplete" value="{$newInstallInComplete}" />
<center class="center" ><h2>ED Systems</h2></center>
<table align="center" border="1" cellpadding="2" cellspacing="1" >
  <tr>
    <td align="center" class="table1" colspan="6">New Installation Entry</td>
  </tr>
  <tr>
    <td align="left" class="table2">Customer : </td>
    <td class="table2">
    	{if $newInstallComplete == 1}
        <select name="partyId" id="partyId" disabled="disabled">
      {else}
      	<select name="partyId" id="partyId">
      {/if}
        <option>Customer Name</option>
        {html_options values=$partyId output=$companyName selected=$companyNameSelected} 
      </select>
      <a href="party.php?redirectFrom=newInstallation" class="link">New Customer</a>  
    </td>
    <td align="left" class="table2">Date : </td>
    <td NOWRAP class="table2">
    	{if $newInstallComplete == 1}
        {html_select_date prefix="insertDate" time="$insertDateSelected" start_year="-3" end_year="+1" month_format="%m" 
         field_order="DMY" day_value_format="%02d" day_extra='disabled=disabled' month_extra='disabled=disabled' year_extra='disabled=disabled'}
      {else}
        {html_select_date prefix="insertDate" time="$insertDateSelected" start_year="-3" end_year="+1" month_format="%m" 
        field_order="DMY" day_value_format="%02d"}
      {/if}
    </td>
    <td align="left" class="table2">Targeted Date : </td>
    <td NOWRAP class="table2">
    	{if $newInstallComplete == 1}
        {html_select_date prefix="targetDate" time="$targetDateSelected" start_year="-3" end_year="+1" month_format="%m" 
         field_order="DMY" day_value_format="%02d" day_extra='disabled=disabled' month_extra='disabled=disabled' year_extra='disabled=disabled'}
      {else}
        {html_select_date prefix="targetDate" time="$targetDateSelected" start_year="-3" end_year="+1" month_format="%m" 
        field_order="DMY" day_value_format="%02d"}
      {/if}
    </td>
  </tr>
</table>
<table align="center" border="1" cellpadding="2" cellspacing="1" >
  <tr>
  	{if $newInstallComplete != 1}
    <td align="center" class="table1">Sr. No.</td>
    {/if}
    {if $newInstallComplete == 1}  
      <td align="center" class="table1">Category</td>
      <td align="center" class="table1">Sub Category</td>
      {if $newInstallInComplete != 1}
        <td align="center" class="table1">Product</td>    
        <td align="center" class="table1">Quantity</td> 
      {/if}  
      <td align="center" class="table1">Description</td>
      <td align="center" class="table1">&nbsp;</td>
      <td align="center" class="table1">&nbsp;</td>
    {else}
      <td align="center" class="table1">Item</td>
      <td align="center" class="table1">Quantity</td>
      <td align="center" class="table1">Description</td>
      <td align="center" class="table1">&nbsp;</td>
      <td align="center" class="table1">&nbsp;</td>
  {/if}
  </tr>
  {if $newInstallComplete == 1}
  {section name="sec" loop=$newInstallationArray}
    <tbody id="mainDiv">  
    <tr id="one">
        <td class="table2" align="center">{$newInstallationArray[sec].categoryName}</td>
        <td class="table2" align="center">{$newInstallationArray[sec].subCategoryName}</td>
        <td class="table2" align="center">{$newInstallationArray[sec].itemName}</td>
        <td class="table2" align="center">{$newInstallationArray[sec].quantity}</td>
        <td size=5 class="table2"><textarea Name="description[]" Rows="1" Cols="16" disabled="disabled">{$newInstallationArray[sec].description}</textarea></td>
    </tr>
    </tbody>
  {/section}
  {else}
    {if $newInstallInComplete == 1}
      {section name="sec" loop=$newInstallationArray}
        <tbody id="mainDiv">  
        <tr id="one">
          <td class="table2"><input type="text" class="srNoClass" name="srNo[]" id="srNo[]" value="1" size="5" DISABLED /></td>
          <td class="table2" NOWRAP>
          <select name="categoryId[]" id="categoryId[]" class="classSubcategory">
            <option value="0">Select Category </option>
            {html_options values=$categoryArray.categoryId output=$categoryArray.categoryName selected=$newInstallationArray[sec].categoryId}
          </select>
          <span>
          <select name="subCategoryId[]" id="subCategoryId[]" class="classItem">
            <option value=0 >Select Subcategory</option>
            {html_options values=$newInstallationArray[sec].subCategoryId output=$newInstallationArray[sec].subCategoryNameArray selected=$newInstallationArray[sec].subCategoryIdSelected}
          </select>
          </span>
          <span>
          <select name="itemId[]" id="itemId[]">
            <option value=0 >Select Item</option>
            {html_options values=$newInstallationArray[sec].itemId output=$newInstallationArray[sec].itemNameArray selected=$newInstallationArray[sec].itemIdSelected}
          </select>
          </span>
          </td>
          <td class="table2" align="center"><input type="text" name="quantity[]" id="quantity[]" value="{$newInstallationArray[sec].quantity}"></td>
          <td size=5 class="table2"><textarea Name="description[]" Rows="1" Cols="16">{$newInstallationArray[sec].description}</textarea></td>
          <td class="table2"><input type="button" value="Add" name="add" class="add"/></td>
          <td class="table2"><input type="button" value="Delete" name="deleteBtn"  class="delete" onclick="deleteRow()"/></td>
        </tr>
        </tbody>
      {/section}
    {else}
      <tbody id="mainDiv">  
      <tr id="one">
        <td class="table2"><input type="text" class="srNoClass" name="srNo[]" id="srNo[]" value="1" size="5" DISABLED /></td>
        <td class="table2" NOWRAP>
        <select name="categoryId[]" id="categoryId[]" class="classSubcategory">
          <option value=0 >Select Category </option>
          {html_options values=$categoryArray.categoryId output=$categoryArray.categoryName}
        </select>
        <span>
        </span>
        <span>
        </span>
        </td>
        <td class="table2" align="center"><input type="text" name="quantity[]" id="quantity[]"></td>
        <td size=5 class="table2"><textarea Name="description[]" Rows="1" Cols="16"></textarea></td>
        <td class="table2"><input type="button" value="Add" name="add" class="add"/></td>
        <td class="table2"><input type="button" value="Delete" name="deleteBtn"  class="delete" onclick="deleteRow()"/></td>
      </tr>
      </tbody>
    {/if}
  {/if}
</table>
<table align="center">
  <tr>
    <td align="center" colspan="8" class="table2"><input class="button" type="submit" name="insertBtn" value="Submit" class="insertBtn" />
      {if $isEdit == 1 || $newInstallComplete == 1 || $newInstallInComplete == 1}
	      <a href="pendingReport.php" class="link">Cancel</a>
	    {/if}
    </td>
  </tr>
</table>
</form>
{include file="footer.tpl"}